//
//  WJIndexTwoOfThirdView.m
//  天气
//
//  Created by dllo on 16/8/24.
//  Copyright © 2016年 WJ. All rights reserved.
//

#import "WJIndexTwoOfThirdView.h"
#import "WJIndexTwoOfThiedCell.h"
#define kWJWidth  [UIScreen mainScreen].bounds.size.width
#define kWJHeight [UIScreen mainScreen].bounds.size.height

@interface WJIndexTwoOfThirdView ()<UICollectionViewDelegate,UICollectionViewDataSource>


@end

@implementation WJIndexTwoOfThirdView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createView];
        
    }
    return self;
}


- (void)createView
{
    // 创建 flowLayout
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(kWJWidth / 7, 70);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.minimumInteritemSpacing = 0;
    
    // 创建CollectiobView
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kWJWidth, 70) collectionViewLayout:flowLayout];
    [self addSubview:self.collectionView];
    self.collectionView .backgroundColor = [UIColor clearColor];
    self.collectionView .delegate = self;
    self.collectionView .dataSource = self;
    self.collectionView.bounces = NO;
    /* 注册cell的重用池 */
    [self.collectionView  registerClass:[WJIndexTwoOfThiedCell class] forCellWithReuseIdentifier:@"WJIndexTwoOfThiedCell"];
    
    
}


//item的个数(方块的个数)
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (self.weather.count) {
        return self.weather.count;
    }else{
        return 0;
    }
}

//cell的样式(可以自定义)
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    WJIndexTwoOfThiedCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WJIndexTwoOfThiedCell" forIndexPath:indexPath];
    
    if (self.weather.count) {
        cell.dic = self.weather[indexPath.row];
    }
    
    return cell;
}






@end
